package com.mujin.keji.collectionsystem.dto;

import android.support.annotation.NonNull;

import com.mujin.keji.collectionsystem.db.domain.VisitApplyBean;

import java.text.Collator;
import java.util.Comparator;
import java.util.Locale;

public class VisitAddressSort implements Comparator<VisitApplyBean> {

    private String sort;

    public VisitAddressSort(String sort) {
        this.sort = sort;
    }

    Collator cmap = Collator.getInstance(Locale.SIMPLIFIED_CHINESE);

    @Override
    public int compare(VisitApplyBean o1, VisitApplyBean o2) {

        if("DESC".equals(sort)){
            //升序
            if (cmap.compare(o1.getAddress(), o2.getAddress())>0){
                return 1;
            }else if (cmap.compare(o1.getAddress(), o2.getAddress())<0){
                return -1;
            }
        }else{
            //降序
            if (cmap.compare(o2.getAddress(), o1.getAddress())>0){
                return 1;
            }else if (cmap.compare(o2.getAddress(), o1.getAddress())<0){
                return -1;
            }
        }

        return 0;
    }

}
